<?php 
namespace Modules\ShopAdmin\Http\Controllers\v1;
use Illuminate\Http\Request;
use Modules\AuthAdmin\Http\Requests\CommonIdRequest;
use Modules\AuthAdmin\Http\Requests\CommonStatusRequest;
use Modules\AuthAdmin\Http\Requests\CommonSortRequest;
use Modules\ShopAdmin\Models\ShopProductType as ShopProductTypeModel;
use Modules\ShopAdmin\Models\ShopProductAttrbuteKey as ShopProductAttrbuteKeyModel;
use Modules\ShopAdmin\Models\ShopProductAttrbuteValue as ShopProductAttrbuteValueModel;
class ProductAttrbuteKeyController extends CommonController
{
	/**
	 * @name  商品属性
	 * @method  GET	
	 * @param  page int 页码
	 * @param  pagesize int 每页条数
	 * @param  name string 属性名称		
	 * @param  product_type_id int 商品分类id		
	 * @param  status int 状态:0=隐藏,1=显示	
	 * @param  created_at string 创建时间	
	 * @param  updated_at string 更新时间	
	 * @return  JSON
	 */
    public function index(Request $request)
    {
		return (new ShopProductAttrbuteKeyModel())->list_data($request->all());
    }
	/**
	 * @name  获取商品分类数据
	 * @method  GET	
	 * @return  JSON
	 */
    public function product_type_list(Request $request)
    {
		return (new ShopProductTypeModel())->product_type_list();
    }
	/**
	 * @name  添加
	 * @method  POST	
	 * @param  product_type_id int 商品分类id	
	 * @param  name string 属性名称	
	 * @param  sort int 排序	
	 * @return  JSON
	 */
    public function store(Request $request)
    {
		$data = $request->all();
		return (new ShopProductAttrbuteKeyModel())->common_create([
			'product_type_id'=>$data['product_type_id'],
			'name'=>$data['name'],
			'sort'=>$data['sort']
		]);
    }
	/**
	 * @name  编辑页面
	 * @method  GET	
	 * @param  id int 商品属性ID	
	 * @return  JSON
	 */
    public function edit(CommonIdRequest $request)
    {	
		$ShopProductAttrbuteKeyModel = new ShopProductAttrbuteKeyModel();
		return $ShopProductAttrbuteKeyModel->api_success([
			'data'=>$ShopProductAttrbuteKeyModel->select('id','name','sort','product_type_id')->find($request->get('id'))
		]);
    }
	/**
	 * @name  编辑提交
	 * @method  PUT	
	 * @param  id int 商品属性ID
	 * @param  product_type_id int 商品分类id	
	 * @param  name string 属性名称	
	 * @param  sort int 排序	
	 * @return  JSON
	 */ 
    public function update(Request $request)
    {
		$data = $request->all();
		return (new ShopProductAttrbuteKeyModel())->common_update($data['id'],[
			'product_type_id'=>$data['product_type_id'],
			'name'=>$data['name'],
			'sort'=>$data['sort']
		]); 
    }
	/**
	 * @name  调整状态
	 * @method  PUT	
	 * @param  id int 商品属性ID
	 * @param  status int 状态（0或1）
	 * @return  JSON
	 */ 
    public function status(CommonStatusRequest $request)
    {
		$data = $request->all();
		return (new ShopProductAttrbuteKeyModel())->common_status_update($data['id'],['status'=>$data['status']]); 
    }
	/**
	 * @name  排序
	 * @method  PUT	
	 * @param  id int 商品属性ID
	 * @param  sort int 排序
	 * @return  JSON
	 */ 
    public function sorts(CommonSortRequest $request)
    {
		$data = $request->all();
		return (new ShopProductAttrbuteKeyModel())->common_sort_update($data['id'],['sort'=>$data['sort']]); 
    }
	
	/**
	 * @name  删除
	 * @method  DELETE	
	 * @param  id int 商品属性ID
	 * @return  JSON
	 */
    public function destroy(CommonIdRequest $request)
    {	
		$id = $request->get('id');
		ShopProductAttrbuteValueModel::where('attrbute_key_id',$id)->delete();
		return (new ShopProductAttrbuteKeyModel())->common_destroy($id);
    }
	
	
	
	
	
	
}
